/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frm_JInterFrameQuanLySach.java
 *
 * Created on Aug 2, 2011, 5:52:07 PM
 */

package gui;


import dao.NhaXuatBanDAO;
import dao.SachDAO;
import dao.TheLoaiDAO;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import pojo.NhaXuatBanPOJO;
import pojo.SachPOJO;
import pojo.TheLoaiPOJO;


/**
 *
 * @author HP
 */
public class frm_JInterFrameQuanLySach extends javax.swing.JInternalFrame {

    /** Creates new form frm_JInterFrameQuanLySach */
// <editor-fold defaultstate="collapsed" desc="1. Cac Thuoc Tinh">
     ArrayList<NhaXuatBanPOJO> dsnxb=new ArrayList<NhaXuatBanPOJO>();
    ArrayList<TheLoaiPOJO> dstheloai=new ArrayList<TheLoaiPOJO>();
    TheLoaiDAO theloaidao=new TheLoaiDAO();
    NhaXuatBanDAO nhaxbdao=new NhaXuatBanDAO();
    SachDAO sachdao=new SachDAO();
    ArrayList<SachPOJO> dssach=new ArrayList<SachPOJO>();
    DefaultTableModel dftablemodel =new DefaultTableModel();//Doi tuong thao tac dong cot cua table
   int stt=1;
// </editor-fold>
   /**
    * Ham Khoi Tao Cac Cot Cho jtblDSSach
    */
    private void InitColumTable()
    {
        dftablemodel.addColumn("STT");
        dftablemodel.addColumn("Ma Sach");
        dftablemodel.addColumn("Ten Sach");
        dftablemodel.addColumn("Gia Ban");
        dftablemodel.addColumn("So Luong Ton");
        this.jtblDSSach.setModel(dftablemodel);
    }
/**
 * Ham Khoi Tao cua Form (Khi run thi ham nay dc chay dau tien)
 */
    public frm_JInterFrameQuanLySach() {
        initComponents();
       InitColumTable();
    }
/**
 *Ham Khoi Tao Cac Gia Tri Cho Combobox
 */
    private void Init()
    {
        try
        {
            DefaultComboBoxModel dfcbxTheLoai=new DefaultComboBoxModel();
            DefaultComboBoxModel dfcbxNhaXB=new DefaultComboBoxModel();

            dstheloai=theloaidao.layDanhSach_TheLoai();

            for(TheLoaiPOJO i: dstheloai)
            {
                Vector vt=new Vector();
                vt.add(i.getMaTheLoai());
                vt.add(i.getTenTheLoai());
                //them mot dong voao model
                dfcbxTheLoai.addElement(vt);
            }
            this.jcmbTheLoai.setModel(dfcbxTheLoai);

            //
            dsnxb=nhaxbdao.layDSNhaXuatBan();

            for(NhaXuatBanPOJO i:dsnxb)
            {
                Vector vt=new  Vector();
                vt.add(i.getMaNhaXuatBan());
                vt.add(i.getTenNhaXuatBan());
                dfcbxNhaXB.addElement(vt);
            }
            this.jcmbxNhaXuatBan.setModel(dfcbxNhaXB);


        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }
/**
 * Ham Xoa Cac Dong Trong table ( quan trong lam do)
 * Muc dich: trong table co nhieu dong trong do,muon khoi tao lai cac gia tri table moi hoan toan
 * thi phai su dung ham nay de xoa tat ca cac dong hien co trong table
 */
public void ClearTableDSSach()
{

    javax.swing.table.DefaultTableModel mode=(DefaultTableModel) this.jtblDSSach.getModel();
   
    for (int i=jtblDSSach.getRowCount()-1;i>=0;i--)
    {
         mode.removeRow(i);
//
    }
}


 private void HienThiDanhSachSach()
{
    dssach=sachdao.layDanhSachCacMaSach();
   ClearTableDSSach() ;
   // InitColumTable();
   // jtblDSSach.removeAll();
    // DefaultTableModel mode=new DefaultTableModel();

    javax.swing.table.DefaultTableModel model=(DefaultTableModel) this.jtblDSSach.getModel();
    stt=1;
     for(SachPOJO i : dssach )
     {
         Vector vt=new Vector();
         vt.add(stt);
         vt.add(i.getMaSach());
         vt.add(i.getTenSach());
         vt.add(i.getGiaBan());
         vt.add(i.getSoLuongTon());
         model.addRow(vt);
         stt++;
     }
   // this.jtblDSSach.setModel(dftablemodel);
}
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jpnThongTinQuanLySach = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jtxtTenSach = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jcmbTheLoai = new javax.swing.JComboBox();
        jcmbxNhaXuatBan = new javax.swing.JComboBox();
        jtxtSoLuongTon = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtxtGiaBan = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtxtMaSach = new javax.swing.JTextField();
        jbtnSuaSach = new javax.swing.JButton();
        jbtnThemSach = new javax.swing.JButton();
        jbtnXoaSach = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtblDSSach = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Quan Ly Sach");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 204, 204));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel8.setText("Quan Ly Thong Tin Sach");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(229, 229, 229)
                .addComponent(jLabel8)
                .addContainerGap(316, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpnThongTinQuanLySach.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255), 2), "Thong Tin Sach"));

        jLabel3.setText("Tên Sách");

        jLabel2.setText("Thể Loại");

        jLabel1.setText("Nhà Xuất Bản");

        jcmbTheLoai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcmbTheLoaiActionPerformed(evt);
            }
        });

        jLabel4.setText("Số Lượng Tồn");

        jLabel5.setText("Giá Bán");

        jLabel7.setText("Mã Sách");

        jbtnSuaSach.setText("Sua");
        jbtnSuaSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSuaSachActionPerformed(evt);
            }
        });

        jbtnThemSach.setText("Them");
        jbtnThemSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThemSachActionPerformed(evt);
            }
        });

        jbtnXoaSach.setText("Xoa");
        jbtnXoaSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnXoaSachActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel7)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(43, 43, 43)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtxtGiaBan, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jbtnXoaSach)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                                .addComponent(jbtnSuaSach)
                                .addGap(18, 18, 18))
                            .addComponent(jtxtSoLuongTon, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(jtxtTenSach, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(jtxtMaSach, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                            .addComponent(jcmbTheLoai, 0, 196, Short.MAX_VALUE)
                            .addComponent(jcmbxNhaXuatBan, 0, 196, Short.MAX_VALUE)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jbtnThemSach)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jcmbxNhaXuatBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jcmbTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtMaSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(12, 12, 12)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jtxtTenSach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jtxtSoLuongTon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtGiaBan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnThemSach, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnXoaSach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnSuaSach, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jpnThongTinQuanLySachLayout = new javax.swing.GroupLayout(jpnThongTinQuanLySach);
        jpnThongTinQuanLySach.setLayout(jpnThongTinQuanLySachLayout);
        jpnThongTinQuanLySachLayout.setHorizontalGroup(
            jpnThongTinQuanLySachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnThongTinQuanLySachLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jpnThongTinQuanLySachLayout.setVerticalGroup(
            jpnThongTinQuanLySachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnThongTinQuanLySachLayout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(160, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(51, 51, 255), 2), "Danh Sach Sach"));

        jtblDSSach.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jtblDSSach.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtblDSSachMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtblDSSach);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addComponent(jpnThongTinQuanLySach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpnThongTinQuanLySach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents
/**
 * Ham formInternalFrameOpened giong nhu su kiem form load 
 * @param evt
 */
    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        try
        {

             Init();
             HienThiDanhSachSach();
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_formInternalFrameOpened

    private void jbtnThemSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemSachActionPerformed
        // TODO add your handling code here:
        try{
            Vector vtnxb=(Vector) this.jcmbxNhaXuatBan.getSelectedItem();
            Vector vttheloai=(Vector) this.jcmbTheLoai.getSelectedItem();
            int matheloai=(Integer)vttheloai.get(0);
            String manbx=(String) vtnxb.get(0);

            SachPOJO sachdto=new SachPOJO();

            sachdto.setMaNhaXuatBan(manbx);
            sachdto.setMaTheLoai(matheloai);
            sachdto.setMaSach(this.jtxtMaSach.getText());
            sachdto.setTenSach(this.jtxtTenSach.getText());
            sachdto.setSoLuongTon(Integer.parseInt(this.jtxtSoLuongTon.getText()));
            sachdto.setGiaBan(Float.parseFloat(this.jtxtGiaBan.getText()));

            if(sachdao.themSach(sachdto)==true)
            {
               Vector vt=new Vector();
               vt.add(stt++);
               vt.add(sachdto.getMaSach());
               vt.add(sachdto.getTenSach());
               vt.add(sachdto.getSoLuongTon());
               vt.add(sachdto.getGiaBan());
               this.dftablemodel.addRow(vt);
            }

        }catch(Exception ex)
        {
             JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbtnThemSachActionPerformed

    private void jcmbTheLoaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcmbTheLoaiActionPerformed
        // TODO add your handling code here:
        try
        {


        }
        catch(Exception ex)
        {
             JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jcmbTheLoaiActionPerformed
/**
 * Ham jtblDSSachMouseClicked : Lay dong duoc chon trong table
 * va lay ra tung thuoc tinh cua dong trng table va hien thi len cac textbox
 * @param evt
 */
    private void jtblDSSachMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtblDSSachMouseClicked
        // TODO add your handling code here:
        try{
            int vt=this.jtblDSSach.getSelectedRow();
            String masach= (String) this.jtblDSSach.getValueAt(vt,1);
            String tensach=(String) this.jtblDSSach.getValueAt(vt, 2);
           // float giaban=Float.parseFloat(this.jtblDSSach.getValueAt(vt, 3).toString().trim());
           // int soluongton=(Integer)this.jtblDSSach.getValueAt(vt, 4);
            this.jtxtMaSach.setText(masach);
            this.jtxtTenSach.setText(tensach);
            this.jtxtSoLuongTon.setText(this.jtblDSSach.getValueAt(vt, 4).toString());
            this.jtxtGiaBan.setText(this.jtblDSSach.getValueAt(vt, 3).toString().trim());
           
        }catch(Exception ex)
        {
              JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jtblDSSachMouseClicked
/**
 * Ham jbtnXoaSachActionPerformed xoa Sach theo ma sach
 * @param evt
 */
    private void jbtnXoaSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXoaSachActionPerformed
        // TODO add your handling code here:
        try
        {
           String masach= this.jtxtMaSach.getText();
           if(sachdao.xoaSach(masach))
           {
                JOptionPane.showMessageDialog(this,"Xóa sách thành công", "Thống báo",JOptionPane.DEFAULT_OPTION);
                HienThiDanhSachSach();
                this.jtxtMaSach.setText("");
                this.jtxtTenSach.setText("");
                this.jtxtGiaBan.setText("");
                this.jtxtSoLuongTon.setText("");
           }
        }catch(Exception ex)
        {
              JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbtnXoaSachActionPerformed

    private void jbtnSuaSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSuaSachActionPerformed
        // TODO add your handling code here:
        try
        {
            Vector vtnxb=(Vector) this.jcmbxNhaXuatBan.getSelectedItem();
            Vector vttheloai=(Vector) this.jcmbTheLoai.getSelectedItem();
            int matheloai=(Integer)vttheloai.get(0);
            String manbx=(String) vtnxb.get(0);

             SachPOJO sachdto=new SachPOJO();

            sachdto.setMaNhaXuatBan(manbx);
            sachdto.setMaTheLoai(matheloai);
            sachdto.setMaSach(this.jtxtMaSach.getText());
            sachdto.setTenSach(this.jtxtTenSach.getText());
            sachdto.setSoLuongTon(Integer.parseInt(this.jtxtSoLuongTon.getText()));
            sachdto.setGiaBan(Float.parseFloat(this.jtxtGiaBan.getText()));

            if(sachdao.capNhatSach(sachdto))
            {
                JOptionPane.showMessageDialog(this,"Cập nhật thành công", "Thống báo",JOptionPane.DEFAULT_OPTION);
                HienThiDanhSachSach();
            }

        }catch(Exception ex)
        {
         JOptionPane.showMessageDialog(this, ex.getMessage(),"Đã xảy ra lỗi",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jbtnSuaSachActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnSuaSach;
    private javax.swing.JButton jbtnThemSach;
    private javax.swing.JButton jbtnXoaSach;
    private javax.swing.JComboBox jcmbTheLoai;
    private javax.swing.JComboBox jcmbxNhaXuatBan;
    private javax.swing.JPanel jpnThongTinQuanLySach;
    private javax.swing.JTable jtblDSSach;
    private javax.swing.JTextField jtxtGiaBan;
    private javax.swing.JTextField jtxtMaSach;
    private javax.swing.JTextField jtxtSoLuongTon;
    private javax.swing.JTextField jtxtTenSach;
    // End of variables declaration//GEN-END:variables

}
